package cc.wsyw126.java.collection.map;

import java.util.*;

/**
 * Created by junpeng.yang on 16/8/31.
 */
public class Values {
    public static void main(String[] args) {
        Map<Integer,String> map = new HashMap<>();
        Collection<String> arrayList = map.values();
        TreeMap<Integer,String> treeMap = new TreeMap<>();
        NavigableMap<Integer,String> navigableMap = new TreeMap<>();
        HashMap<Integer,String> hashMap = new HashMap<>();
        hashMap.put(1,"123");
        String as = hashMap.put(1,"12");
        System.out.println("as = " + as);

        System.out.println("hashMap.get(null) = " + hashMap.get(null));

        Hashtable<Integer,String> hashtable = new Hashtable<>();
        Enumeration enumeration = hashtable.elements();
        while (enumeration.hasMoreElements()){

        }
        hashtable.keys();

    }


    public static Map<Integer, Integer> sortMapByKey(Map<Integer, Integer> map) {
        if (map == null || map.isEmpty()) {
            return null;
        }

        Map<Integer, Integer> sortMap = new TreeMap<>((O1, O2) -> O1 - O2);
        sortMap.putAll(map);

        ArrayList<Map.Entry<Integer, Integer>> l = new ArrayList<>(map.entrySet());
        Collections.sort(l, (arg0, arg1) -> arg0.getKey()-arg1.getKey());

        return sortMap;
    }
}
